package com.csc531.adapters;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import com.csc531.DataTypes.Task;
import com.csc531.views.ClassesView;

/**
 * @author Javier Figueroa
 * Adapter for the ClassesThinList class
 *
 */
public class ClassesSpeechListAdapter extends SpeechListAdapter{


	private static final String TAG = "MyActivity";

	/**
	 * @param context
	 */
	public ClassesSpeechListAdapter(Context context) {
		super(context);
	}

	/**
	 * Appends courses to the list adapter
	 * 
	 * @param newTask course to be added to the adapter
	 */
	public void addCourse(Task newTask) {
		_tasks.add(newTask);

	}

	/**
	 * Populates list with contents of the list adapter
	 */
	public void setExpandedPropertyOnList() {
		int sizeOfList = _tasks.size();

		int i = 0;
		while( i < sizeOfList ) {
			_mExpanded.add(false);
			i++;
		}
	}


	/* (non-Javadoc)
	 * @see com.csc531.adapters.SpeechListAdapter#getView(int, android.view.View, android.view.ViewGroup)
	 */
	public View getView(int position, View convertView, ViewGroup parent) {
		View sv = new View(mContext);

		Task task = _tasks.get(position);
		if (convertView == null) {
			sv = new ClassesView(mContext, task, _mExpanded.get(position));
		} else {
			sv = (ClassesView)convertView;
			((ClassesView) sv).setTitle(task);
			((ClassesView) sv).setDialogue(task);
			((ClassesView) sv).setExpanded(_mExpanded.get(position));
		}

		return sv;
	}

	/**
	 * Toggles visibility of the description field of the task
	 * 
	 * @param position
	 */
	public void toggle(int position) {
		boolean pos = _mExpanded.get(position);
		Log.v(TAG,"pos is: 	"+pos);

		_mExpanded.set(position,!_mExpanded.get(position));
		notifyDataSetChanged();
	}

}
